<?php
$mysql_server_name="localhost"; 
$mysql_username="zj1024";
$mysql_password="z123456789";
$mysql_database="chenchuedu";

header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept,USER_ID,TOKEN");
header("Access-Control-Allow-Methods:HEAD, GET, POST, DELETE, PUT, OPTIONS");
header("Content-Type: text/html; charset=utf-8");

$name = htmlspecialchars($_POST['name']);
$tel = htmlspecialchars($_POST['tel']);
$type = $_POST['type'];

$time = date("Y-m-d H:i:s");
if($name == "" && $tel == ""){
	echo '{"status":"null"}';
	die;
}


$conn=mysql_connect($mysql_server_name, $mysql_username,$mysql_password);

if(!$conn){
    die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db($mysql_database, $conn);

if (!$db_selected)
{
    die ("无法连接数据库，失败原因：" . mysql_error());
}

mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);

$strsql="insert into userinfo(name,tel,type,time) values('".$name."','".$tel."','".$type."','".$time."')";

if (mysql_query($strsql,$conn)){
    echo '{"status":"200"}';
}
else{
    echo '{"status":"500"}';
}
mysql_close($conn);
?>